package com.xbongbong.pro.message.pushset;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.message.domain.entity.PushSetEntity;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.message.base.AbstractPushSet;
import com.xbongbong.pro.message.constant.PushSetConstant;
import com.xbongbong.pro.message.enums.PushObjectTypeEnum;
import com.xbongbong.pro.message.enums.PushTimeTypeEnum;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.model.PushSetModel;
import com.xbongbong.saas.constant.StringConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author long
 * @version v1.0
 * @date 2020/12/8 10:19
 * @since v1.0
 */
public class CluePushSet extends AbstractPushSet {

    private static Integer oneDay = 86400;

    private String pushObject;



    public String getPushObject() {
        return pushObject;
    }



    public void setPushObject(String pushObject) {
        this.pushObject = pushObject;
    }

    @Override
    public PushSetEntity toPushSetEntity(String pushObject, String pushTime,
                                         String attrEntity) {
        setPushObject(pushObject);

        PushSetEntity pushSetEntity = new PushSetEntity();

        pushSetEntity.setAddTime(addTime);
        pushSetEntity.setAttrEntity(attrEntity);
        pushSetEntity.setCorpid(corpid);
        pushSetEntity.setDel(del);
        pushSetEntity.setEnable(enable);
        pushSetEntity.setId(id);
        pushSetEntity.setPushObject(pushObject);
        pushSetEntity.setPushTime(pushTime);
        pushSetEntity.setRefEntity(refEntity);
        pushSetEntity.setSubType(subType);
        pushSetEntity.setType(type);
        pushSetEntity.setUpdateTime(updateTime);
        return pushSetEntity;
    }



    @Override
    public PushSetEntity getPushSet(String corpid, Integer subType,
                                    PushSetModel pushSetModel) {
        Integer type = PushTypeEnum.CLUE_PUSH.getCode();

        Map<String,Object> param = new HashMap<>(16);
        param.put("corpid", corpid);
        param.put("type", type);
        param.put("subType", subType);

        List<PushSetEntity> pushSetList = pushSetModel.findEntitys(param);

        PushSetEntity pushSetEntity;
        if (pushSetList.isEmpty()) {
            pushSetEntity = new PushSetEntity();
            pushSetEntity.setType(type);
            pushSetEntity.setSubType(subType);
            if (Objects.equals(PushTypeEnum.CLUE_ADD_PUSH.getSubCode(), subType) || Objects.equals(PushTypeEnum.CLUE_CHANGE_PUSH.getSubCode(), subType)) {
                pushSetEntity.setEnable(0);
            } else {
                pushSetEntity.setEnable(1);
            }
            JSONObject pushObject = new JSONObject();
            if (Objects.equals(PushTypeEnum.CLUE_ADD_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_ADD_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_ADD));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                jsonObject1.put("enable", 0);
                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(jsonObject1);
                pushObject.put("type", typeArray);
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 1);
                JSONArray managerArray = new JSONArray();
                JSONObject valueObj = new JSONObject();
                valueObj.put("id", "1");
                valueObj.put("name", I18nMessageUtil.getMessage(CommonConstant.FIRST_LEVEL_SUPERVISOR));
                managerArray.add(valueObj);
                managerObject.put("value", managerArray);
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);

            } else if (Objects.equals(PushTypeEnum.CLUE_BACK_PUBLIC.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_BACK_PUBLIC.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_BACK_PUBLIC));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                jsonObject1.put("enable", 1);
                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                jsonObject1.put("editUnenble", 1);
                typeArray.add(jsonObject1);
                pushObject.put("type", typeArray);

               //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 1);
                JSONArray managerArray = new JSONArray();
                JSONObject valueObj = new JSONObject();
                valueObj.put("id", "1");
                valueObj.put("name", I18nMessageUtil.getMessage(CommonConstant.FIRST_LEVEL_SUPERVISOR));
                managerArray.add(valueObj);
                managerObject.put("value", managerArray);
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);

            }else if(Objects.equals(PushTypeEnum.CLUE_TRANSFER_PUBLIC.getSubCode(), subType)){
                pushSetEntity.setTitle(PushTypeEnum.CLUE_TRANSFER_PUBLIC.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_TRANSFER_PUBLIC));
                //分组管理员和分组成员
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.PUBLIC_GROUP_MANAGER.getName());
                jsonObject1.put("enable", 1);
                jsonObject1.put("alias", PushObjectTypeEnum.PUBLIC_GROUP_MANAGER.getAlias());
                jsonObject1.put("editUnenble", 1);
                JSONObject jsonObject2 = new JSONObject();
                jsonObject2.put("name", PushObjectTypeEnum.PUBLIC_GROUP_USER.getName());
                jsonObject2.put("enable", 0);
                jsonObject2.put("alias", PushObjectTypeEnum.PUBLIC_GROUP_USER.getAlias());
                jsonObject2.put("editUnenble", 1);
                typeArray.add(jsonObject1);
                typeArray.add(jsonObject2);
                pushObject.put("type", typeArray);

                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);
            } else if (Objects.equals(PushTypeEnum.CLUE_TEAM_ADD_DEL_MAIN.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_TEAM_ADD_DEL_MAIN.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_TEAM_ADD_MAIN));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                jsonObject1.put("enable", 0);
                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(jsonObject1);
                JSONObject jsonObject2 = new JSONObject();
                jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                jsonObject2.put("enable", 0);
                jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(jsonObject2);
                pushObject.put("type", typeArray);
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 0);
                managerObject.put("value", new ArrayList<>());
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);

            } else if (Objects.equals(PushTypeEnum.CLUE_TEAM_ADD_DEL_SYNERGETIC.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_TEAM_ADD_DEL_SYNERGETIC.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_TEAM_ADD_SYNERGETIC));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                jsonObject1.put("enable", 0);
                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(jsonObject1);
                JSONObject jsonObject2 = new JSONObject();
                jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                jsonObject2.put("enable", 0);
                jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(jsonObject2);
                pushObject.put("type", typeArray);
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 0);
                managerObject.put("value", new ArrayList<>());
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);

            } else if (Objects.equals(PushTypeEnum.CLUE_DISTRIBUTION_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_DISTRIBUTION_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_DISTRIBUTION));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                jsonObject1.put("enable", 0);
                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(jsonObject1);
                JSONObject jsonObject2 = new JSONObject();
                jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                jsonObject2.put("enable", 0);
                jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(jsonObject2);
                JSONObject jsonObject3 = new JSONObject();
                jsonObject3.put("name", PushObjectTypeEnum.TODISTRBUTION.getName());
                jsonObject3.put("enable", 1);
                jsonObject3.put("alias", PushObjectTypeEnum.TODISTRBUTION.getAlias());
                jsonObject3.put("editUnable", 1);
                typeArray.add(jsonObject3);
                pushObject.put("type", typeArray);
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 0);
                managerObject.put("value", new ArrayList<>());
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);

            } else if (Objects.equals(PushTypeEnum.CLUE_HANDOVER_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_HANDOVER_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_HANDOVER));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                jsonObject1.put("enable", 0);
                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(jsonObject1);
                JSONObject jsonObject2 = new JSONObject();
                jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                jsonObject2.put("enable", 0);
                jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(jsonObject2);
                JSONObject jsonObject3 = new JSONObject();
                jsonObject3.put("name", PushObjectTypeEnum.FROMHANDOVER.getName());
                jsonObject3.put("alias", PushObjectTypeEnum.FROMHANDOVER.getAlias());
                jsonObject3.put("enable", 1);
                jsonObject3.put("editUnable", 1);
                typeArray.add(jsonObject3);
                JSONObject jsonObject4 = new JSONObject();
                jsonObject4.put("name", PushObjectTypeEnum.TOHANDOVER.getName());
                jsonObject4.put("alias", PushObjectTypeEnum.TOHANDOVER.getAlias());
                jsonObject4.put("enable", 1);
                jsonObject4.put("editUnable", 1);
                typeArray.add(jsonObject4);
                pushObject.put("type", typeArray);
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 0);
                managerObject.put("value", new ArrayList<>());
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);

            } else if (Objects.equals(PushTypeEnum.CLUE_CHANGE_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_CHANGE_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_CHANGE));
                //type
                JSONArray typeArray = new JSONArray();
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                jsonObject1.put("enable", 1);
                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(jsonObject1);
                JSONObject jsonObject2 = new JSONObject();
                jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                jsonObject2.put("enable", 1);
                jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(jsonObject2);
                pushObject.put("type", typeArray);
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 0);
                managerObject.put("value", new ArrayList<>());
                pushObject.put("manager", managerObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);

            }
//            else if (Objects.equals(PushTypeEnum.CLUE_BIRTHDAY.getSubCode(), subType)) {
//                pushSetEntity.setTitle(PushTypeEnum.CLUE_BIRTHDAY.getName());
//                pushSetEntity.setContent(PushSetConstant.CLUE_BIRTHDAY);
//                //type
//                JSONArray typeArray = new JSONArray();
//                JSONObject jsonObject1 = new JSONObject();
//                jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
//                jsonObject1.put("enable", 1);
//                jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
//                typeArray.add(jsonObject1);
//                pushObject.put("type", typeArray);
//                //manager
//                JSONObject managerObject = new JSONObject();
//                managerObject.put("enable", 0);
//                managerObject.put("value", new ArrayList<>());
//                pushObject.put("manager", managerObject);
//                //user
//                JSONObject userObject = new JSONObject();
//                userObject.put("enable", 0);
//                userObject.put("value", new ArrayList<>());
//                pushObject.put("user", userObject);
//
//                //pushTime
//                JSONObject pushTimeObject = new JSONObject();
//                pushTimeObject.put("period", CustomerPushSet.oneDay);
//                pushTimeObject.put("timeType", PushTimeTypeEnum.ADVANCE.getCode());
//                //是否循环0 不循环 1 循环
//                pushTimeObject.put("loop", 0);
//                pushTimeObject.put("time", 0);
//                //时间控件类型 2具体时间点 1天数
//                pushTimeObject.put("type", 1);
//
//                JSONArray timeArray = new JSONArray();
//                JSONObject timeObject = new JSONObject();
//                timeObject.put("id", 1);
//                timeObject.put("name", "提前");
//                timeArray.add(timeObject);
//                JSONObject timeObject2 = new JSONObject();
//                timeObject2.put("id", 3);
//                timeObject2.put("name", "当天");
//                timeArray.add(timeObject2);
//                pushTimeObject.put("timeArray", timeArray);
//
//                pushSetEntity.setPushTime(pushTimeObject.toJSONString());
//            }

            pushSetEntity.setPushObject(pushObject.toJSONString());
        } else {
            pushSetEntity = pushSetList.get(0);
            if (Objects.equals(PushTypeEnum.CLUE_ADD_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_ADD_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_ADD));

            } else if (Objects.equals(PushTypeEnum.CLUE_BACK_PUBLIC.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_BACK_PUBLIC.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_BACK_PUBLIC));
                // 兼容老数据
                transformOldData(pushSetEntity);
            }else if (Objects.equals(PushTypeEnum.CLUE_TRANSFER_PUBLIC.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_TRANSFER_PUBLIC.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_TRANSFER_PUBLIC));

            } else if (Objects.equals(PushTypeEnum.CLUE_TEAM_ADD_DEL_MAIN.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_TEAM_ADD_DEL_MAIN.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_TEAM_ADD_MAIN));

            } else if (Objects.equals(PushTypeEnum.CLUE_TEAM_ADD_DEL_SYNERGETIC.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_TEAM_ADD_DEL_SYNERGETIC.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_TEAM_ADD_SYNERGETIC));

            } else if (Objects.equals(PushTypeEnum.CLUE_DISTRIBUTION_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_DISTRIBUTION_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_DISTRIBUTION));

            } else if (Objects.equals(PushTypeEnum.CLUE_HANDOVER_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_HANDOVER_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_HANDOVER));

            } else if (Objects.equals(PushTypeEnum.CLUE_CHANGE_PUSH.getSubCode(), subType)) {
                pushSetEntity.setTitle(PushTypeEnum.CLUE_CHANGE_PUSH.getName());
                pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.CLUE_CHANGE));

            }
//            else if (Objects.equals(PushTypeEnum.CLUE_BIRTHDAY.getSubCode(), subType)) {
//                pushSetEntity.setTitle(PushTypeEnum.CLUE_BIRTHDAY.getName());
//                pushSetEntity.setContent(PushSetConstant.CLUE_BIRTHDAY);
//
//            }
        }
        return pushSetEntity;
    }

    private JSONArray formatPushSetType(String typeString, PushTypeEnum pushTypeEnum) {
        JSONArray typeArray = new JSONArray();
        switch (pushTypeEnum) {
            case CLUE_ADD_PUSH:
                JSONObject object = new JSONObject();
                object.put("name", PushObjectTypeEnum.MAINUSER.getName());
                if (typeString.contains(StringConstant.VERTICAL_LINE + PushObjectTypeEnum.MAINUSER.getCode() + StringConstant.VERTICAL_LINE)) {
                    object.put("enable", 1);
                } else {
                    object.put("enable", 0);
                }
                object.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(object);

                JSONObject object1 = new JSONObject();
                object1.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                if (typeString.contains(StringConstant.VERTICAL_LINE + PushObjectTypeEnum.COLLABORATOR.getCode() + StringConstant.VERTICAL_LINE)) {
                    object1.put("enable", 1);
                } else {
                    object1.put("enable", 0);
                }
                object1.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(object1);
                break;
            case CLUE_BACK_PUBLIC:
                break;
            case CLUE_TEAM_ADD_DEL_MAIN:
                break;
            case CLUE_TEAM_ADD_DEL_SYNERGETIC:
                break;
            case CLUE_DISTRIBUTION_PUSH:
                //分配人
                JSONObject disObject = new JSONObject();
                disObject.put("name", PushObjectTypeEnum.TODISTRBUTION.getName());
                disObject.put("enable", 1);
                disObject.put("alias", PushObjectTypeEnum.TODISTRBUTION.getAlias());
                //不允许修改
                disObject.put("editUnable", 1);
                typeArray.add(disObject);

                JSONObject disObject1 = new JSONObject();
                disObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
                disObject1.put("enable", 0);
                disObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(disObject1);

                JSONObject disObject2 = new JSONObject();
                disObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                if (typeString.contains(StringConstant.VERTICAL_LINE + PushObjectTypeEnum.COLLABORATOR.getCode() + StringConstant.VERTICAL_LINE)) {
                    disObject2.put("enable", 1);
                } else {
                    disObject2.put("enable", 0);
                }
                disObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(disObject2);
                break;
            case CLUE_HANDOVER_PUSH:
                JSONObject handoverObject = new JSONObject();
                //移交人
                handoverObject.put("name", PushObjectTypeEnum.TOHANDOVER.getName());
                handoverObject.put("enable", 1);
                handoverObject.put("alias", PushObjectTypeEnum.TOHANDOVER.getAlias());
                handoverObject.put("editUnable", 1);
                typeArray.add(handoverObject);

                JSONObject handoverObject1 = new JSONObject();
                //被移交人
                handoverObject1.put("name", PushObjectTypeEnum.FROMHANDOVER.getName());
                handoverObject1.put("enable", 1);
                handoverObject1.put("alias", PushObjectTypeEnum.FROMHANDOVER.getAlias());
                handoverObject1.put("editUnable", 1);
                typeArray.add(handoverObject1);

                JSONObject handoverObject2 = new JSONObject();
                handoverObject2.put("name", PushObjectTypeEnum.MAINUSER.getName());
                handoverObject2.put("enable", 0);
                handoverObject2.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(handoverObject2);

                JSONObject handoverObject3 = new JSONObject();
                handoverObject3.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                handoverObject3.put("enable", 0);
                handoverObject3.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(handoverObject3);

                break;
            case CLUE_CHANGE_PUSH:
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("name", PushObjectTypeEnum.MAINUSER.getName());
                if (typeString.contains(StringConstant.VERTICAL_LINE + PushObjectTypeEnum.MAINUSER.getCode() + StringConstant.VERTICAL_LINE)) {
                    jsonObject.put("enable", 1);
                } else {
                    jsonObject.put("enable", 0);
                }
                jsonObject.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
                typeArray.add(jsonObject);

                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
                if (typeString.contains(StringConstant.VERTICAL_LINE + PushObjectTypeEnum.COLLABORATOR.getCode() + StringConstant.VERTICAL_LINE)) {
                    jsonObject1.put("enable", 1);
                } else {
                    jsonObject1.put("enable", 0);
                }
                jsonObject1.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
                typeArray.add(jsonObject1);
                break;
            default:
                break;
        }
        return typeArray;
    }

    @Override
    public JSONObject getTimeJson(JSONObject jsonObject) {
        JSONObject object = new JSONObject();
        if (!jsonObject.isEmpty()) {
            object.put("period", jsonObject.getInteger("period") != null ? jsonObject.getInteger("period") : CluePushSet.oneDay);
            object.put("timeType", jsonObject.getInteger("timeType") != null ? jsonObject.getInteger("timeType") : PushTimeTypeEnum.ADVANCE.getCode());
            object.put("loop", jsonObject.getInteger("loop") != null ? jsonObject.getInteger("loop") : 0);
            object.put("time", jsonObject.getInteger("time") != null ? jsonObject.getInteger("time") : 0);
            object.put("type", jsonObject.getInteger("type") != null ? jsonObject.getInteger("type") : 1);
        } else {
            object = new JSONObject();
        }
        return object;
    }



    @Override
    public PushSetEntity getPushSet(String corpid, String attr,
                                    PushSetModel pushSetModel) {
        return null;
    }

    @Override
    public List<PushSetEntity> getPushSet(String corpid, List<String> attrList, PushSetModel pushSetModel, Long templateId) {
        return null;
    }

    public void transformOldData(PushSetEntity pushSetEntity){
        Integer subType = pushSetEntity.getSubType();
        if (Objects.equals(PushTypeEnum.CLUE_BACK_PUBLIC.getSubCode(), subType)){
            // 线索公海池老数据兼容
            String str = pushSetEntity.getPushObject();
            JSONObject pushObject = JSONObject.parseObject(str);
            Object manager = pushObject.get("manager");
            if(Objects.isNull(manager)){
                // 说明是老数据
                //manager
                JSONObject managerObject = new JSONObject();
                managerObject.put("enable", 1);
                JSONArray managerArray = new JSONArray();
                JSONObject valueObj = new JSONObject();
                valueObj.put("id", "1");
                valueObj.put("name", I18nMessageUtil.getMessage(CommonConstant.FIRST_LEVEL_SUPERVISOR));
                managerArray.add(valueObj);
                managerObject.put("value", managerArray);
                pushObject.put("manager", managerObject);
                //dep
                JSONObject depObject = new JSONObject();
                depObject.put("enable", 0);
                depObject.put("value", new ArrayList<>());
                pushObject.put("dep", depObject);
                //role
                JSONObject roleObject = new JSONObject();
                roleObject.put("enable", 0);
                roleObject.put("value", new ArrayList<>());
                pushObject.put("role", roleObject);
                //user
                JSONObject userObject = new JSONObject();
                userObject.put("enable", 0);
                userObject.put("value", new ArrayList<>());
                pushObject.put("user", userObject);
                pushSetEntity.setPushObject(pushObject.toJSONString());
            }
        }
    }


}
